package logic

import (
	"context"
	"errors"
	"short-video-manager/models/mysql"

	"short-video-manager/videorpc/internal/svc"
	"short-video-manager/videorpc/videorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type VideoShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewVideoShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VideoShowLogic {
	return &VideoShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *VideoShowLogic) VideoShow(in *videorpc.VideoShowRequest) (*videorpc.VideoShowResponse, error) {
	// todo: add your logic here and delete this line
	var video mysql.VideoInfo

	if err := video.FindVideoById(mysql.DB, in.VideoId); err != nil {
		return nil, errors.New("视频不存在")
	}
	show := video.VideoShow(mysql.DB, in.VideoId)
	return &videorpc.VideoShowResponse{
		VideoId:       show.VideoId,
		NickName:      show.NickName,
		VideoTitle:    show.VideoTitle,
		VideoCategory: show.VideoCategory,
		VideoLink:     show.VideoLink,
		Url:           show.Url,
	}, nil
}
